< previous page page_676 next page >

Page 676
9f31265bb40b592b1929e18a47ab28e5.gif
intPFonts = Printer.FontCount - 1
For intLoop1 = 0 To Screen.FontCount - 1
   strFont = Screen.Fonts(intLoop1)
   For intLoop2 = 0 To intPFonts
      If strFont = Printer.Fonts(intLoop2) Then
         strGetFont = strFont
      End If
   Next intLoop2
Next intLoop1
The reason for the speed difference has to do with how Visual Basic accesses properties attached to an object. The object name is stored in a symbol table, an internal structure that keeps track of the names of objects. Visual Basic generally uses a hashing algorithm to find the object in this symbol table. Once the object has been located, it uses this location to find the list of properties for this object in another table. Again, Visual Basic has to perform a hashing routine to figure out where that property is located. All of this hashing takes timeif you can eliminate it, youll speed up your code.
Toggle Boolean Data Types Using the Not Operator
To toggle a variable between True and False, use the Not operator instead of an If statement. The Not operator performs a toggle on a Boolean data type, like this:
9f31265bb40b592b1929e18a47ab28e5.gif
boolFlag = True
For lngLoop = 0 To conRepeats
   If boolFlag Then
      boolFlag = False
   Else
      boolFlag = True
   End If
Next
The following method is quicker than the preceding code:
9f31265bb40b592b1929e18a47ab28e5.gif
boolFlag = Not boolFlag
This one is easy to understand, because youre dealing with one line of code versus five lines of code. Also, performing a Not operation results in a bitwise manipulation of the Boolean variable. This is a very quick operation compared to an assignment statement.

 
< previous page page_676 next page >

If you like this book, buy it!